package org.misalen.web.admin.jstltag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.misalen.web.database.repository.mysql.SysWordbookItemRepository;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

public class WordbookEscape extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected SysWordbookItemRepository sysWordbookItemRepository;
	protected WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
	public WordbookEscape() {
		sysWordbookItemRepository = wac.getBean(SysWordbookItemRepository.class);
	}
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = this.pageContext.getOut();
		try {
			out.print(sysWordbookItemRepository.getByCode(wdItemCode).getItemName());
		} catch (Exception e) {
			try {
				out.print("错误");
			} catch (IOException e1) {
				throw new RuntimeException(e1);
			}
		}
		return super.doStartTag();
	}

	@Override
	public void release() {
		wdItemCode = null;
		super.release();
	}

	private String wdItemCode;

	public String getWdItemCode() {
		return wdItemCode;
	}

	public void setWdItemCode(String wdItemCode) {
		this.wdItemCode = wdItemCode;
	}

}
